package Flap::Template::Directive::Fillinform;
use Flap qw/-b Flap::Template::Directive -s -w/;
use constant HAS_END => 1;

sub begin {
    my($dtv, $doc, $ft) = @_;
    my $p = $dtv->{pl}{code}->($doc);
    my %opt;
    if(my $dl = $dtv->{local}){
        $opt{$_} = $dl->{$_}{code}->($doc) for keys %$dl;
    }
    $doc->{tmp}{$dtv->{id}} = [$p, \%opt];
    push @{$ft->{buf}}, \(my $buf = '');
    $dtv->{id} + 1
}

sub end {
    my($dtv, $doc, $ft) = @_;
    my $buf = pop @{$ft->{buf}};
    my($p, $opt) = @{delete $doc->{tmp}{$dtv->{prev_id}}};
    $ft->context->fillinform($buf, $p, $opt) if $p;
    $ft->write($$buf);
    $dtv->{id} + 1
}

sub parse { shift->_parse_include(@_) }

1;
